﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKEA.CMS.Core.IDAL.Mtbl;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.DALFactory;
using HKEA.CMS.Core.Utility;

namespace HKEA.CMS.Core.BLL.Mtbl
{
    public class mtblCustTypebBLL
    {
        private  ImtblCustType IDAL;
        public mtblCustTypebBLL()
        {
            IDAL = DataAccess.CreateImtblCustType();
        }
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static mtblCustTypebBLL GetInstance()
        {
            return new mtblCustTypebBLL();
        }

        /// <summary>
        /// 根据表的id获取一条记录
        /// </summary>
        /// <param name="uid">表的uid</param>
        /// <returns>一个实体（一条记录）</returns>
        public mtblCustType GetEntity(int uid)
        {
            return IDAL.GetEntity(uid);
        }

        public string GetCustType(int custTypeUID)
        {
            return GetCustType(custTypeUID,"");
        }

        /// <summary>
        /// 根据CustTypeUID获取 CustType Name
        /// </summary>
        /// <param name="custTypeUID"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        public string GetCustType(int custTypeUID, string language)
        {
            string ret = string.Empty;
            mtblCustType ent = IDAL.GetEntity(custTypeUID);
            if (ent != null)
            {
                switch (language)
                {
                    case Common.LanguageInfo.ENUSLanguage:
                        ret = ent.CustType_Eng;
                        break;
                    case Common.LanguageInfo.CNLanguage:
                        ret = ent.CustType_Chi;
                        break;
                    case Common.LanguageInfo.ZHHKLanguage:
                        ret = ent.CustType_Chi;
                        break;
                    default:
                        ret = ent.CustType_Eng;
                        break;
                }
            }
            return ret;
        }

        /// <summary>
        /// 根据实体组合参数获取一条记录
        /// </summary>
        /// <param name="ent">实体参数</param>
        /// <returns>一个实体（一条记录）</returns>
        public mtblCustType GetEntity(mtblCustType ent)
        {
            return IDAL.GetEntity(ent);
        }

        /// <summary>
        /// 插入一条记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int InsertENT(mtblCustType ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret= IDAL.InsertENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 物理删除
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int DeleteENT(mtblCustType ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.DeleteENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 修改记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int UpdateENT(mtblCustType ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.UpdateENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 根据条件得到符合条件的结果集，带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<mtblCustType> GetListByENT(mtblCustType ent,PageParam param, string strPropertyName,string strOrderBy)
        {
            List<mtblCustType> list=new List<mtblCustType>();
            if (ent != null && param != null)
            {
                try
                {
                    list= IDAL.GetListByENT(ent,param,strPropertyName,strOrderBy);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }
        /// <summary>
        /// 根据条件得到符合条件的结果集，不带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public List<mtblCustType> GetListByENT(mtblCustType ent)
        {
            List<mtblCustType> list = new List<mtblCustType>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListByENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }
        /// <summary>
        /// 根据条件得到符合条件的记录条数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int GetCountByENT(mtblCustType ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.GetCountByENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 判断是否已存在符合条件的记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public bool IsExist(mtblCustType ent)
        {
            bool ret = false;
            if (ent != null)
            {
                if (GetCountByENT(ent) > 0)
                    ret = true;
            }
            return ret;
        }
    }
}
